package com.example.liaoshanqing

import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.ListView
import androidx.appcompat.app.AppCompatActivity
import java.io.File

class HistoryActivity : AppCompatActivity() {
    private lateinit var historyListView: ListView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_history)

        historyListView = findViewById(R.id.history_list)
        loadHistory()
    }

    private fun loadHistory() {
        val historyList = ArrayList<String>()
        try {
            val file = File(filesDir, "history.txt")
            file.readLines().forEach {
                historyList.add(it)
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
        val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, historyList)
        historyListView.adapter = adapter
    }
}